﻿using System;
using System . Collections . Generic;
using System . Globalization;
using System . Linq;
using System . Text;

namespace WenceyWang . RichMan4L . Weathers
{
	//Todo:完成天气模型
	/// <summary>
	/// 表示天气，它会影响场景的样式，建造，玩家的移动，随机事件等。
	/// </summary>
	public class Weather
	{
		public bool BlockMoving { get { return Wind . Strength >= 950; } }

		public int MoveReduceDistance ( int moveCount )
		{
			if ( Wind . Strength > 600 )
			{
				return Convert . ToInt32 ( Math . Floor ( moveCount * ( Convert . ToDouble ( Wind . Strength - 600 ) / 350d ) ) );
			}
			else
			{
				return 0;
			}
		}

		public bool BlockBuilding { get { return Wind . Strength >= 900; } }

		public long BuildAddMoney ( long price )
		{
			if ( Wind . Strength > 600 )
			{
				return Convert . ToInt64 ( Convert . ToDouble ( price ) * Convert . ToDouble ( Wind . Strength - 600 ) / 300d );
			}
			else
			{
				return 0;
			}
		}

		public bool BlockCard ( Cards . Card card )
		{
			throw new NotImplementedException ( );
		}

		public double BlockBuildingPersent { get; }


		public PrecipitationType PrecipitationType { get; set; }

		/// <summary>
		/// 指示阳光的强度
		/// </summary>
		public int SunshineStrength { get; set; }

		/// <summary>
		/// 指示降水量
		/// </summary>
		public int Precipitation { get; set; }

		public Wind Wind { get; set; }

		public double Temperature { get; set; }

		public static Weather Random ( Calendars . GameDate date )
		{
			Weather weather = new Weather ( );

			Random random = new Random ( );
			double seasonProcessNet = Convert . ToDouble ( date . SeasonProcess ) / Convert . ToDouble ( date . SeasonLenth );

			switch ( date . Season )
			{
				case Seasons . Season . Spring:
					{
						if ( random . Next ( 2 ) == 1 )//和煦的，南风，升温
						{
							weather . Temperature = ( ( seasonProcessNet * seasonProcessNet * 9 ) * 1.25 - 4.8 ) + random . NextNormal ( 0 , 4 , 0 , 10 );

							weather . Wind . Angle = random . NextNormal ( 180 , 100 , 90 , 270 );
							weather . Wind . Strength = Convert . ToInt32 ( random . NextNormal ( 350 , 200 , 0 , 600 ) );

							if ( weather . Wind . Strength <= 450 )
							{
								int rain = random . Next ( 1 , 11 );

								if ( rain == 1 )//下雨
								{
									weather . Precipitation = Convert . ToInt32 ( random . NextNormal ( 100 , 50 , 20 , 200 ) );
									weather . SunshineStrength = Convert . ToInt32 (
 random . NextNormal ( 100 , 50 , 20 , 200 ) );
									if ( weather . Temperature >= 5 )
									{
										weather . PrecipitationType = PrecipitationType . Rainy;
									}
									else
									{
										if ( weather . Temperature >= 0 )
										{
											weather . PrecipitationType = PrecipitationType . Sleet;
										}
										else
										{
											weather . PrecipitationType = PrecipitationType . Snowy;
										}
									}
								}
								else
								{
									weather . Precipitation = 0;
									weather . SunshineStrength = Convert . ToInt32 ( random . NextNormal ( 150 , 50 , 20 , 300 ) );
								}
							}
							else
							{
								weather . Precipitation = 0;
								weather . SunshineStrength = Convert . ToInt32 ( random . NextNormal ( 175 , 60 , 50 , 400 ) );
							}
						}
						else//犀利的，北风，降温
						{
							weather . Temperature = ( ( seasonProcessNet * seasonProcessNet * 9 ) * 1.25 - 4.8 ) + random . NextNormal ( 0 , 4 , -10 , 0 );
							weather . Wind . Angle = random . NextNormal ( 0 , 100 , -90 , 90 );
							if ( weather . Wind . Angle < 0 )
							{
								weather . Wind . Angle += 360;
							}
							weather . Wind . Strength = Convert . ToInt32 ( random . NextNormal ( 350 , 200 , 200 , 1000 ) );

							if ( weather . Wind . Strength <= 450 )
							{
								int rain = random . Next ( 1 , 21 );
								if ( rain == 1 )//下雨
								{
									weather . Precipitation = Convert . ToInt32 ( random . NextNormal ( 300 , 50 , 20 , 500 ) );
									weather . SunshineStrength = Convert . ToInt32 (
 random . NextNormal ( 100 , 50 , 20 , 200 ) );
									if ( weather . Temperature >= 5 )
									{
										weather . PrecipitationType = PrecipitationType . Rainy;
									}
									else
									{
										if ( weather . Temperature >= 0 )
										{
											weather . PrecipitationType = PrecipitationType . Sleet;
										}
										else
										{
											weather . PrecipitationType = PrecipitationType . Snowy;
										}
									}
								}
								else
								{
									weather . Precipitation = 0;
									weather . SunshineStrength = Convert . ToInt32 ( random . NextNormal ( 200 , 50 , 20 , 400 ) );
								}
							}
							else
							{
								weather . Precipitation = 0;
								weather . SunshineStrength = Convert . ToInt32 ( random . NextNormal ( 250 , 60 , 50 , 500 ) );
							}
						}

						break;
					}
				case Seasons . Season . Summer:
					{
						if ( random . Next ( 2 ) == 1 )
						{

						}
						else
						{

						}
						break;
					}
				case Seasons . Season . Autumn:
					{
						break;
					}
				case Seasons . Season . Winter:
					{
						break;
					}
				default: { throw new NotImplementedException ( ); }
			}
			return weather;
		}

	}
}
